﻿using ZYCommon;
using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;

namespace TextEditor
{
   
    /// <summary>
    /// 分割线属性设置
    /// </summary>
    public class HRuleTagProvider : SmartTagProvider
    {
        public override void GetCommands(ArrayList myList)
        {
            if (base.Element is ZYTextHRule)
            {
                myList.Add(new SmartTagItem(this, 1, "设置线的粗细"));
                myList.Add(new SmartTagItem(this, 2, "设置颜色"));
                myList.Add(new SmartTagItem(this, 3, "实线/虚线"));
            }
        }

        public override Point GetPos()
        {
            return new Point(base.Element.RealLeft, (base.Element.RealTop - base.OwnerControl.SmartTagSize()) - 3);
        }

        public override bool HandleCommand(SmartTagItem item)
        {
            ZYTextHRule element = base.Element as ZYTextHRule;
            if (element != null)
            {
                switch (item.ID)
                {
                    case 1:
                    {
                        string strData = dlgInputBox.InputBox("请输入线的粗细,输入的值必须在1到10之间", "系统输入", element.LineHeight.ToString());
                        if (StringCommon.IsInteger(strData))
                        {
                            element.LineHeight = StringCommon.ToInt32Value(strData, element.LineHeight);
                            base.OwnerDocument.RefreshElement(element);
                        }
                        break;
                    }
                    case 2:
                        using (ColorDialog dialog = new ColorDialog())
                        {
                            dialog.Color = element.ForeColor;
                            if (dialog.ShowDialog(base.OwnerControl) == DialogResult.OK)
                            {
                                element.ForeColor = dialog.Color;
                                base.OwnerDocument.RefreshElement(element);
                                return true;
                            }
                        }
                        break;    
                    case 3:
                        element.DashStyle = element.DashStyle == 1 ? 0 : 1;
                        base.OwnerDocument.RefreshElement(element);
                        break;
                }
            }
            return true;
        }

        public override bool isEnable()
        {
            return ((base.OwnerDocument.Content.SelectLength == 0) && (base.OwnerDocument.Content.CurrentElement is ZYTextHRule));
        }

        public override int ImageIndex
        {
            get
            {
                return 0x13;
            }
        }
    }
}

